/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JDialogSettings.java
 *
 * Created on 15/02/2011, 19:37:20
 */
package systole.view.settings;

import javax.swing.JFileChooser;
import org.jdesktop.application.Action;
import systole.utils.ImageUtils;

/**
 *
 * @author jmj
 */
public class JDialogSettings extends javax.swing.JDialog {

    private ControllerSettings controllerSettings;

    /** Creates new form JDialogSettings
     * @param parent
     * @param controllerSettings
     */
    public JDialogSettings(java.awt.Frame parent, ControllerSettings controllerSettings) {
        super(parent, true);
        initComponents();
        this.controllerSettings = controllerSettings;
        this.setIconImage(ImageUtils.buildImage("resources/icons/settings/advancedsettings16.png"));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPnlCenter = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPnlFiles = new javax.swing.JPanel();
        jTxtImportDir = new javax.swing.JTextField();
        jTxtExportDir = new javax.swing.JTextField();
        jBtnImport = new javax.swing.JButton();
        jBtnExport = new javax.swing.JButton();
        jLblImport = new javax.swing.JLabel();
        jLblExport = new javax.swing.JLabel();
        jPnlDefaultValues = new javax.swing.JPanel();
        jLblSegmentsAmount = new javax.swing.JLabel();
        jSpnAmount = new javax.swing.JSpinner();
        jLblCorrelaion = new javax.swing.JLabel();
        jSpnCorrelation = new javax.swing.JSpinner();
        jLblKindCorrelation = new javax.swing.JLabel();
        jCmbCorrelation = new javax.swing.JComboBox();
        jPnlWS = new javax.swing.JPanel();
        jLblURL = new javax.swing.JLabel();
        jTxtURL = new javax.swing.JTextField();
        jChkOnStart = new javax.swing.JCheckBox();
        jChkOnClose = new javax.swing.JCheckBox();
        jPnlTop = new javax.swing.JPanel();
        jXHeader1 = new org.jdesktop.swingx.JXHeader();
        jPnlBottom = new javax.swing.JPanel();
        jBtnOk = new javax.swing.JButton();
        jBtnCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(systole.view.SystoleApp.class).getContext().getResourceMap(JDialogSettings.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setModal(true);
        setName("Form"); // NOI18N
        setResizable(false);

        jPnlCenter.setName("jPnlCenter"); // NOI18N
        jPnlCenter.setLayout(new java.awt.BorderLayout());

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N
        jTabbedPane1.setPreferredSize(new java.awt.Dimension(370, 233));

        jPnlFiles.setName("jPnlFiles"); // NOI18N
        jPnlFiles.setPreferredSize(new java.awt.Dimension(370, 205));

        jTxtImportDir.setEditable(false);
        jTxtImportDir.setName("jTxtImportDir"); // NOI18N

        jTxtExportDir.setEditable(false);
        jTxtExportDir.setText(resourceMap.getString("jTxtExportDir.text")); // NOI18N
        jTxtExportDir.setName("jTxtExportDir"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(systole.view.SystoleApp.class).getContext().getActionMap(JDialogSettings.class, this);
        jBtnImport.setAction(actionMap.get("selectImportDirectory")); // NOI18N
        jBtnImport.setIcon(resourceMap.getIcon("jBtnImport.icon")); // NOI18N
        jBtnImport.setText(resourceMap.getString("jBtnImport.text")); // NOI18N
        jBtnImport.setToolTipText(resourceMap.getString("jBtnImport.toolTipText")); // NOI18N
        jBtnImport.setName("jBtnImport"); // NOI18N
        jBtnImport.setPreferredSize(new java.awt.Dimension(36, 36));

        jBtnExport.setAction(actionMap.get("selectExportDirectory")); // NOI18N
        jBtnExport.setIcon(resourceMap.getIcon("jBtnExport.icon")); // NOI18N
        jBtnExport.setText(resourceMap.getString("jBtnExport.text")); // NOI18N
        jBtnExport.setToolTipText(resourceMap.getString("jBtnExport.toolTipText")); // NOI18N
        jBtnExport.setName("jBtnExport"); // NOI18N
        jBtnExport.setPreferredSize(new java.awt.Dimension(36, 36));

        jLblImport.setText(resourceMap.getString("jLblImport.text")); // NOI18N
        jLblImport.setName("jLblImport"); // NOI18N

        jLblExport.setText(resourceMap.getString("jLblExport.text")); // NOI18N
        jLblExport.setName("jLblExport"); // NOI18N

        javax.swing.GroupLayout jPnlFilesLayout = new javax.swing.GroupLayout(jPnlFiles);
        jPnlFiles.setLayout(jPnlFilesLayout);
        jPnlFilesLayout.setHorizontalGroup(
            jPnlFilesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlFilesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPnlFilesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPnlFilesLayout.createSequentialGroup()
                        .addComponent(jLblExport)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 172, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPnlFilesLayout.createSequentialGroup()
                        .addGroup(jPnlFilesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPnlFilesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jTxtExportDir)
                                .addComponent(jTxtImportDir, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLblImport))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPnlFilesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jBtnExport, javax.swing.GroupLayout.PREFERRED_SIZE, 42, Short.MAX_VALUE)
                            .addComponent(jBtnImport, 0, 0, Short.MAX_VALUE))))
                .addGap(136, 136, 136))
        );

        jPnlFilesLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jBtnExport, jBtnImport});

        jPnlFilesLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jTxtExportDir, jTxtImportDir});

        jPnlFilesLayout.setVerticalGroup(
            jPnlFilesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlFilesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLblImport)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPnlFilesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jTxtImportDir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtnImport, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLblExport)
                .addGap(4, 4, 4)
                .addGroup(jPnlFilesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jTxtExportDir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtnExport, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(66, Short.MAX_VALUE))
        );

        jPnlFilesLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jBtnExport, jBtnImport});

        jPnlFilesLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jTxtExportDir, jTxtImportDir});

        jTabbedPane1.addTab(resourceMap.getString("jPnlFiles.TabConstraints.tabTitle"), jPnlFiles); // NOI18N

        jPnlDefaultValues.setName("jPnlDefaultValues"); // NOI18N
        jPnlDefaultValues.setPreferredSize(new java.awt.Dimension(370, 205));

        jLblSegmentsAmount.setText(resourceMap.getString("jLblSegmentsAmount.text")); // NOI18N
        jLblSegmentsAmount.setName("jLblSegmentsAmount"); // NOI18N

        jSpnAmount.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(8), Integer.valueOf(1), null, Integer.valueOf(1)));
        jSpnAmount.setToolTipText(resourceMap.getString("jSpnAmount.toolTipText")); // NOI18N
        jSpnAmount.setName("jSpnAmount"); // NOI18N

        jLblCorrelaion.setText(resourceMap.getString("jLblCorrelaion.text")); // NOI18N
        jLblCorrelaion.setName("jLblCorrelaion"); // NOI18N

        jSpnCorrelation.setModel(new javax.swing.SpinnerNumberModel(95, 1, 100, 1));
        jSpnCorrelation.setToolTipText(resourceMap.getString("jSpnCorrelation.toolTipText")); // NOI18N
        jSpnCorrelation.setName("jSpnCorrelation"); // NOI18N

        jLblKindCorrelation.setText(resourceMap.getString("jLblKindCorrelation.text")); // NOI18N
        jLblKindCorrelation.setName("jLblKindCorrelation"); // NOI18N

        jCmbCorrelation.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jCmbCorrelation.setToolTipText(resourceMap.getString("jCmbCorrelation.toolTipText")); // NOI18N
        jCmbCorrelation.setName("jCmbCorrelation"); // NOI18N

        javax.swing.GroupLayout jPnlDefaultValuesLayout = new javax.swing.GroupLayout(jPnlDefaultValues);
        jPnlDefaultValues.setLayout(jPnlDefaultValuesLayout);
        jPnlDefaultValuesLayout.setHorizontalGroup(
            jPnlDefaultValuesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlDefaultValuesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPnlDefaultValuesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLblKindCorrelation, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLblSegmentsAmount, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLblCorrelaion, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(18, 18, 18)
                .addGroup(jPnlDefaultValuesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCmbCorrelation, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jSpnAmount, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jSpnCorrelation, javax.swing.GroupLayout.DEFAULT_SIZE, 76, Short.MAX_VALUE))
                .addGap(133, 133, 133))
        );

        jPnlDefaultValuesLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jSpnAmount, jSpnCorrelation});

        jPnlDefaultValuesLayout.setVerticalGroup(
            jPnlDefaultValuesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlDefaultValuesLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jPnlDefaultValuesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLblKindCorrelation)
                    .addComponent(jCmbCorrelation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPnlDefaultValuesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLblSegmentsAmount)
                    .addComponent(jSpnAmount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPnlDefaultValuesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLblCorrelaion)
                    .addComponent(jSpnCorrelation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(87, Short.MAX_VALUE))
        );

        jPnlDefaultValuesLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jSpnAmount, jSpnCorrelation});

        jTabbedPane1.addTab(resourceMap.getString("jPnlDefaultValues.TabConstraints.tabTitle"), jPnlDefaultValues); // NOI18N

        jPnlWS.setName("jPnlWS"); // NOI18N

        jLblURL.setText(resourceMap.getString("jLblURL.text")); // NOI18N
        jLblURL.setName("jLblURL"); // NOI18N

        jTxtURL.setText(resourceMap.getString("jTxtURL.text")); // NOI18N
        jTxtURL.setName("jTxtURL"); // NOI18N

        jChkOnStart.setText(resourceMap.getString("jChkOnStart.text")); // NOI18N
        jChkOnStart.setName("jChkOnStart"); // NOI18N

        jChkOnClose.setText(resourceMap.getString("jChkOnClose.text")); // NOI18N
        jChkOnClose.setName("jChkOnClose"); // NOI18N

        javax.swing.GroupLayout jPnlWSLayout = new javax.swing.GroupLayout(jPnlWS);
        jPnlWS.setLayout(jPnlWSLayout);
        jPnlWSLayout.setHorizontalGroup(
            jPnlWSLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlWSLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPnlWSLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPnlWSLayout.createSequentialGroup()
                        .addComponent(jLblURL)
                        .addGap(18, 18, 18)
                        .addComponent(jTxtURL, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jChkOnClose)
                    .addComponent(jChkOnStart))
                .addContainerGap(31, Short.MAX_VALUE))
        );
        jPnlWSLayout.setVerticalGroup(
            jPnlWSLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlWSLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPnlWSLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLblURL)
                    .addComponent(jTxtURL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jChkOnStart)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jChkOnClose)
                .addContainerGap(97, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(resourceMap.getString("jPnlWS.TabConstraints.tabTitle"), jPnlWS); // NOI18N

        jPnlCenter.add(jTabbedPane1, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPnlCenter, java.awt.BorderLayout.CENTER);

        jPnlTop.setName("jPnlTop"); // NOI18N
        jPnlTop.setPreferredSize(new java.awt.Dimension(400, 55));
        jPnlTop.setLayout(new java.awt.BorderLayout());

        jXHeader1.setDescription(resourceMap.getString("jXHeader1.description")); // NOI18N
        jXHeader1.setIcon(resourceMap.getIcon("jXHeader1.icon")); // NOI18N
        jXHeader1.setName("jXHeader1"); // NOI18N
        jXHeader1.setTitle(resourceMap.getString("jXHeader1.title")); // NOI18N
        jPnlTop.add(jXHeader1, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPnlTop, java.awt.BorderLayout.PAGE_START);

        jPnlBottom.setName("jPnlBottom"); // NOI18N
        jPnlBottom.setPreferredSize(new java.awt.Dimension(420, 40));

        jBtnOk.setAction(actionMap.get("confirm")); // NOI18N
        jBtnOk.setText(resourceMap.getString("jBtnOk.text")); // NOI18N
        jBtnOk.setToolTipText(resourceMap.getString("jBtnOk.toolTipText")); // NOI18N
        jBtnOk.setName("jBtnOk"); // NOI18N
        jPnlBottom.add(jBtnOk);

        jBtnCancel.setAction(actionMap.get("cancel")); // NOI18N
        jBtnCancel.setText(resourceMap.getString("jBtnCancel.text")); // NOI18N
        jBtnCancel.setToolTipText(resourceMap.getString("jBtnCancel.toolTipText")); // NOI18N
        jBtnCancel.setName("jBtnCancel"); // NOI18N
        jPnlBottom.add(jBtnCancel);

        getContentPane().add(jPnlBottom, java.awt.BorderLayout.PAGE_END);

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtnCancel;
    private javax.swing.JButton jBtnExport;
    private javax.swing.JButton jBtnImport;
    private javax.swing.JButton jBtnOk;
    private javax.swing.JCheckBox jChkOnClose;
    private javax.swing.JCheckBox jChkOnStart;
    private javax.swing.JComboBox jCmbCorrelation;
    private javax.swing.JLabel jLblCorrelaion;
    private javax.swing.JLabel jLblExport;
    private javax.swing.JLabel jLblImport;
    private javax.swing.JLabel jLblKindCorrelation;
    private javax.swing.JLabel jLblSegmentsAmount;
    private javax.swing.JLabel jLblURL;
    private javax.swing.JPanel jPnlBottom;
    private javax.swing.JPanel jPnlCenter;
    private javax.swing.JPanel jPnlDefaultValues;
    private javax.swing.JPanel jPnlFiles;
    private javax.swing.JPanel jPnlTop;
    private javax.swing.JPanel jPnlWS;
    private javax.swing.JSpinner jSpnAmount;
    private javax.swing.JSpinner jSpnCorrelation;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTxtExportDir;
    private javax.swing.JTextField jTxtImportDir;
    private javax.swing.JTextField jTxtURL;
    private org.jdesktop.swingx.JXHeader jXHeader1;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the jTxtExportDir
     */
    public javax.swing.JTextField getjTxtExportDir() {
        return jTxtExportDir;
    }

    /**
     * @return the jTxtImportDir
     */
    public javax.swing.JTextField getjTxtImportDir() {
        return jTxtImportDir;
    }

    private String getDirectoryPath(String currentPath) {
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(new java.io.File(currentPath));
        chooser.setDialogTitle("Seleccionar directorio");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            return chooser.getSelectedFile().getPath();
        }
        return currentPath;
    }

    @Action
    public void selectImportDirectory() {
        this.jTxtImportDir.setText(this.getDirectoryPath(this.jTxtImportDir.getText()));
    }

    @Action
    public void selectExportDirectory() {
        this.jTxtExportDir.setText(this.getDirectoryPath(this.jTxtExportDir.getText()));
    }

    @Action
    public void confirm() {
        this.controllerSettings.ok();
    }

    @Action
    public void cancel() {
        this.controllerSettings.cancel();
    }

 
    /**
     * @return the jSpnAmount
     */
    public javax.swing.JSpinner getjSpnAmount() {
        return jSpnAmount;
    }

    /**
     * @return the jCmbCorrelation
     */
    public javax.swing.JComboBox getjCmbCorrelation() {
        return jCmbCorrelation;
    }

    /**
     * @return the jSpnCorrelation
     */
    public javax.swing.JSpinner getjSpnCorrelation() {
        return jSpnCorrelation;
    }

  

    

}
